<template>
  <div class="home-container fadeIn">
    <div class='home-content'>
      <div class="">
        <el-form :model='formSet'  status-icon ref='formSet' label-width='100px' size="medium">

          <div class='item-box'>
            <el-form-item prop='appConfigName' label="配置名称：" >
              <el-input type='text' v-model='formSet.appConfigName' placeholder='请输入应用名称' auto-complete='off'/>
            </el-form-item>
          </div>
          <div class='item-box'>
            <el-form-item prop='appConfigValue' label="配置值：" >
              <el-input type='text' v-model='formSet.configValue' placeholder='请输入值' auto-complete='off'/>
            </el-form-item>
          </div>

          <div class='item-box'>
            <el-form-item>
              <el-button class='submit' type="primary" @click='onSubmit'>保存</el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </div>
  </div>

</template>

<script>
import { mapActions } from 'vuex';
import { queryString } from '@/utils';

export default {
  name: 'HomeChildSetting',
  data() {
    return {
      formSet: {
        appConfigName: '',
        appConfigValue: '',
        configId: '',
        userId: this.$getLS('userId'),
      },
      options: [{
        value: '1',
        label: '1.游戏',
      }, {
        value: '2',
        label: '2.应用',
      }],
      isSubmit: false,
    };
  },
  computed: {
  },
  mounted() {
    if (this.$route.query) {
      this.formSet = {
        appConfigName: this.$route.query.appConfigName,
        configValue: this.$route.query.appConfigValue,
        userId: this.$getLS('userId'),
        configId: this.$route.query.id,
      };
    }
  },
  components: {
  },
  methods: {
    ...mapActions('homeOperate', [
      'modify',
    ]),
    onSubmit() {
      this.$refs.formSet.validate((valid) => {
        if (valid && !this.isSubmit) {
          // 用户注册  baseURL
          return this.modify(queryString(this.formSet))
          .then((res) => {
            setTimeout(() => {
              this.isSubmit = false;
            }, 5000);
            if (res.data === true) {
              this.$router.push({ path: '/main/homeOperate' });
            } else {
              this.$message.warning('操作失败！');
            }
          });
        }
        return false;
      });
    },

  },
};
</script>

<style lang='scss' src='@/scss/pages/home_index.scss'/>
<style lang='scss' scope src='@/scss/pages/child.scss'/>
